package com.zhdl.modules.common.service.impl;

import com.zhdl.modules.common.dao.ProcessRecordsDao;
import com.zhdl.modules.common.entity.ProcessRecords;
import com.zhdl.modules.common.service.ProcessRecordsService;
import com.zhdl.modules.common.web.req.ProcessRecordsReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

@Slf4j
@Service
public class ProcessRecordsServiceImpl implements ProcessRecordsService {

    @Resource
    private ProcessRecordsDao processRecordsDao;

    @Override
    public void updateProcessDao(ProcessRecordsReq req){
        Optional<ProcessRecords> byId = processRecordsDao.findById(req.getId());
        if (byId.isPresent()) {
            ProcessRecords processRecords = byId.get();
            processRecords.setProcessStep(req.getProcessStep());
            processRecords.setProcessModel(req.getProcessModel());
            processRecords.setSelfChecking(req.isSelfChecking());
            processRecordsDao.save(processRecords);
        } else {
            log.info("当前对象:" + byId.getClass().getSimpleName() + ",为空!!!");
        }
    }

    @Override
    public void saveProcessDao(ProcessRecords req){
        processRecordsDao.save(req);
    }

    @Override
    public ProcessRecords findById(int id){
        Optional<ProcessRecords> byId = processRecordsDao.findById(id);
        return byId.orElse(null);
    }
}
